import reqests from "../utils/requests.js"
import {STATUS_CODE} from "../utils/variables.js"


/**
 * 保存
 * @param {Object} data
 */
export async function addGoodsApi(data) {
	const res = await reqests.request({
		url: "/goods",
		data,
		method: "POST"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"添加地址失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res;
}


/**
 * 分类查询查询
 * @param {Object} data
 */
export async function queryGoodsListApi(data){
	const res = await reqests.request({
		url: "/list/query",
		data,
		method: "PUT"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"添加地址失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res.data;
}


/**
 * 首页查询商品数据
 * @param {Object} data
 */
export async function indexGoodsListApi(data){
	const res = await reqests.request({
		url: "/list/index",
		data,
		method: "PUT"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"添加地址失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res.data;
}

/**
 * 获取商品列表信息
 * @param {Object} data
 */
export async function listGoodsListApi(data){
	const res = await reqests.request({
		url: "/list/list",
		data,
		method: "PUT"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"添加地址失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res.data;
}

/**
 * 商品详细信息
 * @param {Object} data
 */
export async function getGoodsDetailApi(id){
	const res = await reqests.request({
		url: `/list/detail/${id}`,
		method: "GET"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"添加地址失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res.data;
}


/**
 * 获取售卖商品列表
 * @param {Object} data
 */
export async function getSellListApi(data){
	const res = await reqests.request({
		url: `/goods/sell/list`,
		data,
		method: "PUT"
	})
	if(res.code!=STATUS_CODE.SUCCESS_CODE){
		uni.showToast({
			title:"添加地址失败，请稍后重试",
			icon:'none',
			duration:2000
		})
		return;
	}
	return res.data;
}